package com.shujia.wyh.mr.youhua;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class RandomWeather {
    public static void main(String[] args) throws Exception {
        //创建日期格式
        DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        long start = sdf.parse("2000-01-01 00:00:00").getTime();
        long end = sdf.parse("2022-12-31 00:00:00").getTime();
        long difference = end - start;

        BufferedWriter bw = new BufferedWriter(new FileWriter("hadoop/src/main/java/com/shujia/wyh/mr/youhua/weather.txt"));

        for (int i = 0; i < 10000; i++) {
            //随机生成时间2000-2023
            Date date = new Date(start + (long) (Math.random() * difference));
            //随机生成一个温度
            int temperature = -20 + (int) (Math.random() * 60);
            //打印生成的结果
            System.out.println(sdf.format(date) + "\t" + temperature);
            bw.write(sdf.format(date) + "\t" + temperature);
            bw.newLine();
            bw.flush();
        }
        bw.close();
    }
}